//
// Created by suzhen on 18-1-16.
//

#pragma once

#include <hacks/base/hacks_conf.h>

namespace hacks::net {

    class ip_addr {
    public:
        virtual ~ip_addr();

        ip_addr(const std::string &s_addr_, uint16_t port_);

    public:

        virtual sa_family_t get_domain() const = 0;

        const std::string &get_addr() const;

        std::uint16_t get_port() const;

    protected:
        std::string s_addr_;
        std::uint16_t port_;
    };

    class ip4_addr : public ip_addr {
    public:
        ip4_addr(const std::string &s_addr_,
                 uint16_t port_);

        struct sockaddr_in get_sock_addr4() const {
            return sock_in4;
        }

        sa_family_t get_domain() const override;

    private:
        struct sockaddr_in sock_in4;
    };

    class ip6_addr : public ip_addr {
    public:
        ip6_addr(const std::string &s_addr_, uint16_t port_);

        struct sockaddr_in6 get_sock_addr6() const {
            return sock_in6;
        }

        sa_family_t get_domain() const override;

    private:
        struct sockaddr_in6 sock_in6;
    };

}



